<template>
  <WithDialog
    :visible.sync="dialogVisible"
    title="物品录入"
    :confirm-btn-loading="loading"
    @confirm="handleConfirm"
    @cancel="handleCancel"
  >
    <el-alert
      title="温馨提示"
      type="warning"
      :closable="false"
      style="margin-bottom: 10px;"
    >
      主计量单位通常是商品的最小计量单位，
      而辅助单位则可能是更大的计量单位。
      例如纸巾，主计量单位为 “包”，辅助单位可以为 “箱”,
      辅助单位中的换算比例是多少包为一箱，假设20包为一箱，那么辅助单位的换算比例为 20。
    </el-alert>
    <Form
      ref="formRef"
      :model="model"
      :goods-type-list="goodsTypeList"
    />
  </WithDialog>
</template>
<script>
import WithDialog from '@/components/WithDialog/withDialog.vue'
import Form from './Form.vue'
export default {
  name: '',
  components: {
    WithDialog,
    Form
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },

    goodsTypeList: {
      type: Array,
      default: () => []
    },

    loading: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      model: {
        name: '',
        // parent_id: null,
        remark: null,
        unit: '',
        unitList: []
        // is_directory: 0
      }
    }
  },
  computed: {
    dialogVisible: {
      get() {
        return this.visible
      },
      set(value) {
        this.$emit('update:visible', value)
      }
    }
  },
  methods: {
    async handleConfirm() {
      const res = await this.$refs.formRef.validate()
      if (!res) return this.$message.error('请提交正确的信息')
      this.$emit('confirm', this.model)
      // this.close()
    },

    handleCancel() {
      this.close()
    },

    close() {
      // this.model = this.$options.data().model
      this.$emit('update:visible', false)
    },

    resetFields() {
      this.$refs.formRef.resetFields()
    }
  }
}
</script>
<style lang="scss" scoped>
::v-deep(.el-dialog__body) {
  padding-top: 0;
}
</style>
